<template>
	<view>
		<view class="drop_down_menu">
			<view class="menu_item" :class="{'active':item.id == tabs.choose.id}" v-for="(item,index) in tabs.list"
				:key="index" @click="chooseTabs(item)">
				<view class="item_title ellipsis-1">
					{{ getLabel(item) }}
				</view>
				<view class="icon">
					<image class="gray" src="@/static/icon/search/triangle-gray-icon.png" mode="widthFix"></image>
					<image class="black" src="@/static/icon/search/triangle-black-icon.png" mode="widthFix"></image>
				</view>
			</view>
		</view>
	</view>

</template>

<script>
	export default {
		label: "dropDownMenu",
		props: {
			screenItem: {
				type: Object,
				default: () => {
					return {}
				}
			},
			screenTabType: {
				type: String,
				default: 'normal'
			}
		},
		created() {
			if (this.screenTabType == 'normal') {
				this.tabs.list = [{
					name: 'disease',
					label: '按疾病',
					type: 1,
					id: 0
				}, {
					name: 'department',
					label: '按科室',
					type: 1,
					id: 1
				}, {
					name: 'location',
					label: '全国',
					type: 1,
					id: 2
				}, {
					name: '',
					label: '筛选',
					type: 2,
					id: 3
				}]
			} else if (this.screenTabType == 'reservation') {
				this.tabs.list = [{
						name: 'location',
						label: '全国',
						type: 1,
						id: 0
					},
					{
						name: 'hospitaltype',
						label: '医院类型',
						type: 2,
						id: 1
					},
					{
						name: 'hospitallevel',
						label: '医院等级',
						type: 2,
						id: 2
					}
				]
			}
		},
		data() {
			return {
				tabs: {
					list: [],
					choose: {}
				}
			};
		},
		computed: {
			getLabel() {
				return (item) => {
					if ((item.id == this.tabs.choose.id) && this.screenItem && this.screenItem.id) {
						return this.screenItem.departName || this.screenItem.name || item.label
					} else {
						return item.label
					}
				}
			}
		},
		methods: {
			chooseTabs(item) {
				this.tabs.choose = item
				this.$emit('onchange', item)
			}
		},
	}
</script>

<style lang="scss" scoped>
	.drop_down_menu {
		padding: 20rpx 30rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;

		.menu_item {
			flex: 1;
			display: flex;
			align-items: center;
			justify-content: center;

			&.active {
				.item_title {
					font-weight: bold;
					color: #333333;
				}

				.icon {
					.gray {
						display: none;
						transition: all 0.3s;
					}

					.black {
						display: block;
						transition: all 0.3s;
					}
				}
			}

			.item_title {
				font-size: 30rpx;
				color: #999999;
			}

			.icon {
				width: 20rpx;
				height: 20rpx;
				margin-left: 15rpx;
				display: flex;
				align-items: center;
				justify-content: center;

				.gray {
					display: block;
					transition: all 0.3s;
				}

				.black {
					display: none;
					transition: all 0.3s;
				}

				image {
					width: 100%;
					height: 100%;
				}
			}
		}
	}

	.select {}
</style>